package com.example.yls.demoa;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements IOnTimeChangeListener{
    private Button btnStart;
    private TextView txtTime;
    private TextView txtChange;
    private MyReceiver receiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        receiver = new MyReceiver(MainActivity.this);
        IntentFilter intentFilter = new IntentFilter();

        intentFilter.addAction("TIME_CHANGE");
        registerReceiver(receiver,intentFilter);

        txtTime = findViewById(R.id.tex_time);
        txtChange = findViewById(R.id.tex_change);
        btnStart = findViewById(R.id.btn_start);
        btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,MyService.class);
                startService(intent);
            }
        });
    }

    @Override
    public void show(String str) {
        txtTime.setText(str);
    }
    @Override
    public void changePlace(String str) {
        txtChange.setText(str);
    }

}
